import json


# 加s的两个方法 和 json字符串 有关系
jsonstr = """
    [
   {
		"name": "霸座男",
		"age": 45
	},
	{
		"name": "龙哥",
		"age": 37
	},
	{
		"name": "柳青",
		"age": 35
	},
	{
		"name": "熊帅",
		"age": 30
	}
]
"""

# loads : str-->dict或者list
data_list = json.loads(jsonstr)

# dumps : dict或者list --> json_str
data_list = [
   {
		"name": "霸座男",
		"age": 45
	},
	{
		"name": "龙哥",
		"age": 37
	},
	{
		"name": "柳青",
		"age": 35
	},
	{
		"name": "熊帅",
		"age": 30
	}
]
data_str = json.dumps(data_list)



# 不加s的方法和 fp=filepath文件有关系

# load 从文件里面读取内容 直接转换成 或者list
fp = open("data.json", 'r', encoding='utf-8')
data_list = json.load(fp)

# dump 直接将dict和list 写入指定文件
list = [
    {
        "title":"霸座男嚣张",
        "url":"他家的地址"
    },
    {
        "title": "柳青 求可怜",
        "url": "sdfsfddfsurl"
    },
]

# liststr = json.dumps(list)
# with open("01list.json", 'w') as f:
#     f.write(liststr)

fp = open("01list.json", 'w', encoding='utf-8')
json.dump(list,fp)

print(data_list)
print(type(data_list))